/**
 * Created by yuzhang on 2018/4/26.
 */

import { NativeModules } from 'react-native'

const trackNative = NativeModules.YuanXinTrack

export function send (event) {
  let shouldSend = !(__DEV__ || global.NoTrackSend)
  let tip = shouldSend ? '' : '(DEV环境不发送)'
  console.log(`Track数据${tip}`, JSON.stringify(event, null, 2))
  if (shouldSend) {
    trackNative.recordTrackLog(event)
  }
}

export function sendLogin (event) {
  let shouldSend = !(__DEV__ || global.NoTrackSend)
  let tip = shouldSend ? '' : '(DEV环境不发送)'
  console.log(`Login Track数据${tip}`, JSON.stringify(event, null, 2))
  if (shouldSend) {
    trackNative.recordLoginLog(event)
  }
}

export function sendAnyThing (event) {
  let shouldSend = !(__DEV__ || global.NoTrackSend)
  let tip = shouldSend ? '' : '(DEV环境不发送)'
  console.log(`Track数据${tip}，任意数据格式`, JSON.stringify(event, null, 2))
  if (shouldSend) {
    trackNative.recordAnyTrackLog(event)
  }
}
